<?php

include "./lib/src/skey.php";

$upload_url = base_url('uploads');
$admin_url = base_url('otakkanan');
$kirim_url = base_url('otakkiri');

$mapdir = "<a href='$admin_url/' class='taut'>Home</a> &gt; ";

$menu = $this->uri->segment(3, "all");

if(empty ($pesan))
{
	$pesan = '';
}


switch($menu)
{
	case "baru":
	
		$mapdir .= "
			<a href='$admin_url/pengguna' class='taut'>Pengguna</a>
			&gt; 
			<b>Tambah Baru</b>
		";
		
		$isipage = "
				<div id='content2'>
						<h3>Tambah Pengguna Baru</h3>
							<div class='isicontent2'>
								<h4 style='color:red'>$pesan</h4>
							</div>
							
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/penggunabaru' method='post' onsubmit='return validasi_pengguna(this)' enctype='multipart/form-data' >
								
									<table>
										<tbody>
											<tr>
												<td class='left'>Nama * </td>
												<td class='right'> <input name='nama' type='text' placeholder='Nama' /> </td>
											</tr>
											<tr>
												<td class='left'>Email *</td>
												<td class='right'> <input name='email' type='email' placeholder='Email' /></td>
											</tr>
											<tr>
												<td class='left'>Username (nama untuk login) * </td>
												<td class='right'> <input name='username' type='text' placeholder='Username' /></td>
											</tr>
											
											<tr>
												<td class='left'>Password * </td>
												<td class='right'> <input name='password' type='password' /></td>
											</tr>
											<tr>
												<td class='left'>Password (konfirmasi) *</td>
												<td class='right'> <input name='password2' type='password' /></td>
											</tr>
											<tr>
												<td class='left'>Jenis Kelamin * </td>
												<td class='right'> 
													<select name='jk'>
														<option value='1'>Laki-laki</option>
														<option value='0'>Perempuan</option>
													</select>
												</td>
											</tr>
											<tr>
												<td class='left'>Tanggal Lahir * </td>
												<td class='right'> <input name='tgllahir' type='text' id='tgllahir' />
													<div class='note'>Format tanggal : yyyy-mm-dd</div>
												</td>
											</tr>
											<tr>
												<td class='left'>Level Akses * </td>
												<td class='right'>
													<select name='level'>
														<option value='1'>Administrator</option>
														<option value='2' selected='selected'>Mitra / Partner</option>
													</select>
												</td>
											</tr>
											
											<tr>
												<td class='left'>&nbsp;</td>
												<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
											</tr>
											<tr>
												<td class='left'> &nbsp; </td>
												<td class='right'><input type='submit' value='Tambah'> &nbsp; <input type='reset' value='Ulang'></td>
											</tr>
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
		
	;
	break;
	
	case "edit":
	
		$mapdir .= "
			<a href='$admin_url/pengguna' class='taut'>Pengguna</a>
			&gt; 
			<b>Edit Pengguna</b>
		";
		
		$usrid = $this->input->get('uid');
		$hasil = $this->adminmodel->get_data_pengguna($usrid);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				
				$nama = html_escape($hasil2->nama);
				$email = html_escape($hasil2->email);
				$username = html_escape($hasil2->username);
				
				if($hasil2->jk == TRUE)
				{
					$jeniskelamin = "<option value='1' selected='selected'>Laki-laki</option>
									<option value='0'>Perempuan</option>";
				}else{
					$jeniskelamin = "<option value='1'>Laki-laki</option>
					<option value='0' selected='selected'>Perempuan</option>";
				}
				
				if($hasil2->status == TRUE)
				{
					$status = "<option value='1' selected='selected'>Aktif</option> <option value='0'>Suspend</option>";
				}
				else
				{
					$status = "<option value='1'>Aktif</option> <option value='0' selected='selected'>Suspend</option>";
				}
				
				$tampil = "
							<tr>
								<td class='left'>Nama </td>
								<td class='right'> <input name='nama' type='text' value='$nama' /></td>
							</tr>
							<tr>
								<td class='left'>E-mail </td>
								<td class='right'> <input name='email' type='email' value='$email' /> </td>
							</tr>
							<tr>
								<td class='left'>Username </td>
								<td class='right'> $username</td>
							</tr>
							<tr>
								<td class='left'>Password </td>
								<td class='right'> <input name='password' type='password' /></td>
							</tr>
							<tr>
								<td class='left'>Password (konfirmasi) </td>
								<td class='right'> <input name='password2' type='password' /></td>
							</tr>
							<tr>
								<td class='left'>Jenis Kelamin </td>
								<td class='right'> 
									<select name='jk'>
										$jeniskelamin
									</select>
								</td>
							</tr>
							<tr>
								<td class='left'>Tanggal Lahir </td>
								<td class='right'> <input name='tgllahir' type='text' id='tgllahir' value='$hasil2->tgllahir' />
									<div class='note'>Format tanggal : yyyy-mm-dd</div>
								</td>
							</tr>
							<tr>
								<td class='left'>Gambar </td>
								<td class='right'> <input name='gambar' type='file' />
									<div class='note'>Anda Juga bisa menambahkan  Gambar/Foto</div>
								</td>
							</tr>
							<tr>
								<td class='left'>Level  </td>
								<td class='right'> 
									<select name='level'>
										<option value='1'>Administrator</option>
										<option value='2' selected='selected'>Partner</option>
									</select>
								</td>
							</tr>
							<tr>
								<td class='left'>Status </td>
								<td class='right'> <select name='status'>$status</select></td>
							</tr>
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><input type='hidden' name='uid' value='$usrid' /><input type='hidden' name='oldgambar' value='$hasil2->gambar' />
								<input type='submit' value='Ubah'> &nbsp; <input type='reset' value='Ulang'></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Edit Pengguna</h3>
							<div class='isicontent2'>
								<h4 style='color:red'>$pesan</h4>
							</div>
							
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/updatepengguna' method='post' onsubmit='return validasi_pengguna(this)' enctype='multipart/form-data' >
								
									<table>
										<tbody>
										
											$tampil
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
	;
	break;
	
	
	
	case "detail":
	
		$mapdir .= "
			<a href='$admin_url/pengguna'>Pengguna</a>
			&gt; 
			<b>Detail</b>
		";
		
		$usrid = $this->input->get('uid');
		$hasil = $this->adminmodel->get_data_pengguna($usrid);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				
				$nama = html_escape($hasil2->nama);
				$email = html_escape($hasil2->email);
				$username = html_escape($hasil2->username);
				$tgllahir = date("d M Y", strtotime($hasil2->tgllahir));
				$tglreg = date("d M Y", strtotime($hasil2->tglreg));
				
				if($hasil2->jk == TRUE)
				{
					$jk = "Pria";
				}
				else
				{
					$jk = "Wanita";
				}
				
				if($hasil2->level == 1)
				{
					$level = "Administrator";
				}
				else
				{
					$level = "User";
				}
				
				$status = "";
				if($hasil2->status == FALSE)
				{
					$status = "(<b>Suspend</b>)";
				}
				
				$tampil = "";
				if( ! empty($hasil2->gambar))
				{
					$tampil .= "<tr><td class='left'><img alt='gambar profile' src='$upload_url/pengguna/$hasil2->gambar' style='width:60%; border:0px' /> </td>
								<td class='right'>&nbsp;</td></tr>";
				}
				
				$tampil .= "<tr>
								<td class='left'>Nama </td>
								<td class='right'> 
									$nama $status 
									<a href='$admin_url/pengguna/edit?uid=$usrid' class='taut'>Edit</a> &nbsp; <a href='$kirim_url/hapuspengguna?uid=$usrid' onclick='return konfirmhapus()' title='Hapus Pengguna'>Hapus</a>
								</td>
							</tr>
							<tr>
								<td class='left'>E-mail </td>
								<td class='right'> $email </td>
							</tr>
							<tr>
								<td class='left'>Username </td>
								<td class='right'> $username</td>
							</tr>
							<tr>
								<td class='left'>Jenis Kelamin </td>
								<td class='right'> $jk</td>
							</tr>
							<tr>
								<td class='left'>Tanggal Lahir </td>
								<td class='right'> $tgllahir</td>
							</tr>
							<tr>
								<td class='left'>Bergabung sejak </td>
								<td class='right'> $tglreg</td>
							</tr>
							<tr>
								<td class='left'>Level Akses </td>
								<td class='right'> $level</td>
							</tr>
							
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>&nbsp;</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><a href='$admin_url/pengguna' class='taut'>&lt; Kembali</a></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Detail Pengguna</h3>
							<div class='isicontent2'>
							
								<table>
									<tbody>
									
										$tampil
									
									</tbody>
								</table>
									
							</div>
							
						</div>
			";
	;
	break;
	
	default:
	
		$mapdir = "
			<a href='$admin_url/' class='taut'>Home</a>
			&gt; 
			<b>Pengguna</b>
		";
		
		$awal = $this->input->get("awal");
		$pengguna = $this->adminmodel->get_pengguna($awal);
		$datapengguna = "";
		
		foreach($pengguna AS $udata)
		{
			$usrid = $udata->uid;
			$username = html_escape($udata->username);
			$nama = html_escape($udata->nama);
			
			if($usrid != $uid && $usrid != 1)
			{
			$datapengguna .= "
				<tr>
				<td class='left'>$username ($nama)</td>
				<td class='right'> 
					<a href='$admin_url/pengguna/detail?uid=$usrid'>Detail</a> &nbsp; <!--<a href='$admin_url/pengguna/edit?uid=$usrid' class='taut'>Edit</a>--> &nbsp; <a href='$kirim_url/hapuspengguna?uid=$usrid' onclick='return konfirmhapus()' title='Hapus Pengguna'>Hapus</a>
				</td>
				</tr>";
			}
		}
		
		
		$config['base_url'] = $admin_url.'/pengguna?users=go';
		$config['total_rows'] = $this->adminmodel->hitung_data('uid','dn_users');
		$config['per_page'] = 20; 
		$config['anchor_class'] = 'class="taut"';
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'awal';

		$this->pagination->initialize($config); 
		$halaman = $this->pagination->create_links();
		
		$isipage = "
				<div id='content2'>
						<h3>Daftar Pengguna</h3>
							<div class='isicontent2'>
							 <table>
								<tbody>
									<tr><td class='left'><a href='$admin_url/pengguna/baru' class='taut'>Tambah Pengguna</a></td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									$datapengguna
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'><a href='$admin_url/pengguna/baru' class='taut'>Tambah Pengguna</a></td><td class='right'>$halaman</td></tr>
								</tbody>
							 </table>
							</div>
							
					</div>
			";
	;
	break;
}


$data['map_dir'] = $mapdir;
$data['isi_page'] = $isipage;
$data['site_title'] = 'Pengguna - Dadan Network';
$data['base_url'] = base_url();
$data['tahun_sekarang'] = date("Y");

$this->parser->parse('template/admin', $data);


/* End of file pengguna.php */
/* Location: ./application/views/admin/pengguna.php */
